package com.webex.ta.hydra.gui.menu;

import com.webex.ta.hydra.core.PropertyManager;
import com.webex.ta.hydra.plugin.Plugin;
import com.webex.ta.hydra.plugin.PluginManager;

import javax.swing.*;

/**
 * Created by Cisco WebEx.
 * User: vegaz
 * Date: 2010-9-30
 * Time: 12:37:11
 */
public class PluginsProvider implements DynamicMenuProvider {
    public void update(JMenu menu) {
//        JMenuItem pluginmgr = MenuFactory.makeMenuItem("Plugin Manager...", 'E', "Plugin Manager...", ActionNames.PLUGIN_MGR);
//        pluginmgr.setIcon(HydraUtils.getImage("plugins.gif"));
//        menu.add(pluginmgr);
        Plugin[] plugins = PluginManager.getInstance().getActivatedPlugins();
        boolean separatorAdded = false;

        for (Plugin plugin : plugins) {
            String pluginName = plugin.getName();
            String menuName = "plugin." + pluginName + ".menu";
            String menuItems = PropertyManager.getInstance().getProperty(menuName);
            if (menuItems != null) {
                JMenuItem mi = new DynamicMenu(menuName, pluginName);
                if (!separatorAdded) {
                    menu.addSeparator();
                    separatorAdded = true;
                }
                menu.add(mi);
            }
        }
    }

    public boolean updateEveryTime() {
        return false;
    }
}
